package yhao.infra.feature.rabbitmq.demo;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

//@Configuration
public class RabbitMqConfiguration {
    //queue定义
    public final static String Q_TEST = "hello.queue1";

    //exchange定义
    public final static String EXCHANGE_DEMO_TOPIC = "topicDemoExchange";

    //route定义
    public final static String Q_TEST_TO_DEMO_TOPIC = "hello.queue1.*";


    @Autowired
    private Environment env;

    //声明队列
    @Bean
    public Queue helloQueue() {
        return new Queue(Q_TEST, true); // true表示持久化该队列
    }

    //声明交互器
    @Bean
    public TopicExchange demoExchange() {
        return new TopicExchange(EXCHANGE_DEMO_TOPIC);
    }

    //绑定
    @Bean
    public Binding helloQueueToDemoExchange(Queue helloQueue,TopicExchange demoExchange) {
        return BindingBuilder.bind(helloQueue).to(demoExchange).with(Q_TEST_TO_DEMO_TOPIC);
    }


}
